/**
 * Created by Joseph on 2014/5/21.
 */
$(document).ready(function(){
    initClickable();
});

function initClickable(){

    var addImgTxtSelector = ".add-imgtxt form input, .add-imgtxt form select, .add-imgtxt form textarea";
    var editImgTxtSelector = ".edit-imgtxt form input, .edit-imgtxt form select, .edit-imgtxt form textarea";


    //返回按钮
    $("#add-return, #edit-return").click(function(){
        showAllImgTxt();
    });


    //重置按钮
    $("#add-reset, #edit-reset").click(function(){
        var currentId = $(this).attr("id");
        var currentSelector;
        if(currentId == "add-reset")
        currentSelector = addImgTxtSelector;
        else
        currentSelector = editImgTxtSelector;
        $(currentSelector).each(function(){
            $(this).val("");
        });
    });


    //确定按钮
    $("#add-ok, #edit-ok").click(function(){
        var flag = true;
        var currentId = $(this).attr("id");
        var currentSelector;
        if(currentId == "add-ok")
            currentSelector = addImgTxtSelector;
        else
            currentSelector = editImgTxtSelector;
        $(currentSelector).each(function(){
            var value = $(this).val();
            if(value==undefined||value==null||value=="")
                flag = false;
        });
        if(!flag){
            event.preventDefault();
            alert("请输入完整信息");
        }
    });

    //添加按钮
    $("#add").click(function(){
        showAddImgTxt();
    });

    //编辑按钮
    $(".update").click(function(){
        showEditImgTxt();
    });
}

//显示所有图文
function showAllImgTxt() {
    $(".imgtxt-display").show();
    $(".add-imgtxt").hide();
    $(".edit-imgtxt").hide();
}
//显示添加图文
function showAddImgTxt() {
    $(".imgtxt-display").hide();
    $(".add-imgtxt").show();
    $(".edit-imgtxt").hide();
}
//显示编辑图文
function showEditImgTxt() {
    $(".imgtxt-display").hide();
    $(".add-imgtxt").hide();
    $(".edit-imgtxt").show();
}